package com.ruoyi.userManagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.userManagement.domain.XuanUser;
import com.ruoyi.userManagement.service.IXuanUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/userManagement/user")
public class XuanUserController extends BaseController
{
    @Autowired
    private IXuanUserService xuanUserService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(XuanUser xuanUser)
    {
        startPage();
        List<XuanUser> list = xuanUserService.selectXuanUserList(xuanUser);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XuanUser xuanUser)
    {
        List<XuanUser> list = xuanUserService.selectXuanUserList(xuanUser);
        ExcelUtil<XuanUser> util = new ExcelUtil<XuanUser>(XuanUser.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:query')")
    @GetMapping(value = "/{usrId}")
    public AjaxResult getInfo(@PathVariable("usrId") Long usrId)
    {
        return success(xuanUserService.selectXuanUserByUsrId(usrId));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XuanUser xuanUser)
    {
        return toAjax(xuanUserService.insertXuanUser(xuanUser));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XuanUser xuanUser)
    {
        return toAjax(xuanUserService.updateXuanUser(xuanUser));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('userManagement:user:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usrIds}")
    public AjaxResult remove(@PathVariable Long[] usrIds)
    {
        return toAjax(xuanUserService.deleteXuanUserByUsrIds(usrIds));
    }
}
